//
//  HomePageViewController.m
//  HunBa.
//
//  Created by 维Sir on 16/5/23.
//  Copyright © 2016年 fubang. All rights reserved.
//

#import "HomePageVieController.h"

#import "ZzCoverFlow.h"
#import "CityTableViewCell.h"
#import "LBTableViewCell.h"
#import "SetRequest.h"
#import "NetWorkModel.h"
#import "Api.h"
#import "TwoTableViewCell.h"
@interface HomePageVieController (){

    NSArray *arr;

}

@end

@implementation HomePageVieController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self bar];
    
    // Do any additional setup after loading the view.
}
-(void)bar{
 [self.navigationController.navigationBar setBarTintColor: [UIColor colorWithRed:244/255.0 green:169/255.0 blue:39/255.0 alpha:1]];
}
-(void)getdata{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    //    [dic setValue:@"token" forKey:@"TOKEN"];
    //    [dic setValue:[NSNumber numberWithDouble:12] forKey:@"countRen"];
    [[SetRequest sharedInstance]getRequestWithURL:@"http://192.168.1.123/api/Recommend/slide"
    postParems:dic content:^(NetWorkModel *model){
        if(model.error){
            NSLog(@"请求失败");
        }else{
            if ([model.responseDic[@"error_code"] intValue] == 0) {
                _dataSource = model.responseDic[@"data"];
                [self.tableView reloadData];
            }
        }
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section== 1){
        return 1;
    }else{
        return 5;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:( NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 300;
    } if (indexPath.section == 1) {
        return 127;
    }else{
        return 120;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSDictionary * DIC = [_dataSource objectAtIndex:indexPath.row];
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellOne"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.view.frame = CGRectMake(0, 0, 320, 350);
        NSMutableArray *sourceImages = [NSMutableArray arrayWithCapacity:20];
        for (int i = 0; i <20 ; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d-.jpg", i]];
            [sourceImages addObject:image];
        }
        CoverFlow *coverFlow = [CoverFlow coverFlowViewWithFrame:CGRectMake(0,-70,[UIScreen mainScreen].bounds.size.width, self.view.frame.size.width+80) andImages:sourceImages sideImageCount:1 sideImageScale:0.7 middleImageScale:0.9];
        [cell.contentView addSubview:coverFlow];
        return cell;
    }if (indexPath.section == 1){
        TwoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TwoTableViewCell"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"TwoTableViewCell" owner:self options:nil] lastObject];
            self.view.backgroundColor = [UIColor clearColor];
            self.view.frame = CGRectMake(0, 20, 100, 50);
            NSMutableArray *sourceImagess = [NSMutableArray arrayWithCapacity:5];
            for (int i = 1; i <5 ; i++) {
                UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
                [sourceImagess addObject:image];
            }
            CoverFlow *coverFlow = [CoverFlow coverFlowViewWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width , self.view.frame.size.width) andImages:sourceImagess sideImageCount:1 sideImageScale:1 middleImageScale:1];
            [cell.contentView addSubview:coverFlow];
        }
        
        return cell;
    }if (indexPath.section == 2) {
        LBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LBTableViewCell"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LBTableViewCell" owner:self options:nil] lastObject];
        }
        return cell;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
